package game;

import org.lwjgl.util.vector.Vector3f;

public class Entity {
	protected World world;
	protected Vector3f pos, rot;
	public float speed = 0.1f;
	public float height = 10f;

	public Entity(World world, Vector3f pos) {
		this.world = world;
		this.pos = pos;
		rot = new Vector3f();
	}

	public void update(int delta) {

	}

	public void render() {

	}

	public void move(Vector3f vec) {
		if (vec.x != 0 && vec.z != 0) {
			move(new Vector3f(vec.x, 0, 0));
			move(new Vector3f(0, vec.y, 0));
			move(new Vector3f(0, 0, vec.z));
			return;
		}
		if (!collision(vec.x, vec.y, vec.z)) {
			pos.x += vec.x;
			pos.y += vec.y;
			pos.z += vec.z;
		}
	}

	private boolean collision(float xa, float ya, float za) {
		for (int i = 0; i < world.getBoxes().size(); i++) {
			float ox = world.getBoxes().get(i).getPos().x;
			float oy = world.getBoxes().get(i).getPos().y;
			float oz = world.getBoxes().get(i).getPos().z;

			float oxs = world.getBoxes().get(i).getSize().x;
			float oys = world.getBoxes().get(i).getSize().y;
			float ozs = world.getBoxes().get(i).getSize().z;

			if (pos.x + xa <= -ox && pos.x + xa >= -(ox + oxs)) {
				if (pos.y + ya <= -oy && pos.y + ya >= -(oy + oys)) {
					if (pos.z + za <= -oz && pos.z + za >= -(oz + ozs)) {
						System.out.println("intersects!");
						return true;
					}
				}
			}
		}

		return false;
	}

	public void setRot(Vector3f rot) {
		this.rot = rot;
	}

	public Vector3f getPos() {
		return pos;
	}

	public Vector3f getRot() {
		return rot;
	}
}
